﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>用户管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="../demo.css" rel="stylesheet" type="text/css" />
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
    html,body
    {
        width:100%;
        height:100%;
        border:0;
        margin:0;
        padding:0;
        overflow:visible;
    }
    </style>
</head>
<body >   
    <div class="mini-toolbar" style="padding:2px;border:0;">
        <table style="width:100%;">
            <tr>
            <td style="width:100%;"> 
                 <!-- <a class="mini-button" iconCls="icon-add" onclick="newRow()" plain="true">增加</a>
                 <a class="mini-button" iconCls="icon-add" onclick="editRow()" plain="true">编辑</a>-->
                 <a class="mini-button" iconCls="icon-download" onclick="downloadData()"  plain="true">数据下载</a> 
                 <a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>
            </td>
            <td style="white-space:nowrap;"> 
                <label style="font-family:Verdana;"> 注册时间: </label>
                <input id="datebegin" class="mini-datepicker" format="yyyy-MM-dd HH" timeFormat="HH" showTime="true"/>~<input id="dateend" class="mini-datepicker" format="yyyy-MM-dd HH" timeFormat="HH" showTime="true"/>
                <!-- <label style="font-family:Verdana;"> 状态: </label>
                <input name="type" id="statetype" class="mini-combobox" showNullItem="true" style="width: 100px;"  data="state"/>-->
                <label style="font-family:Verdana;" >用户ID:</label>
                <input class="mini-textbox" id="key" />
                 <label style="font-family:Verdana;" >IP:</label>
                <input class="mini-textbox" id="ip" />
                <a class="mini-button" iconCls="icon-search" plain="true" onclick="search();">查询</a>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit" style="height:100px;">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
            url="/ios/pages/User/list.do"  idField="id"
            sizeList="[5,10,20,50]" allowResize="true" pageSize="20" 
		    allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
		    editNextOnEnterKey="true">
            <div property="columns">
                <div type="checkcolumn" style="width:5px;"></div>
                <div type="indexcolumn" style="width:5px;"></div>
                <div field="userid" width="120" headerAlign="center" allowSort="true" renderer="onUserIDRenderer">用户id</div> 
                <div field="username" width="120" headerAlign="center" allowSort="true">用户昵称</div>
                <div field="dintegral" width="120" headerAlign="center" allowSort="true">获取积分</div>      
                <div field="integral" width="120" headerAlign="center" allowSort="true">总积分</div>         
                <div field="huIntegral" width="100" allowSort="true"   headerAlign="center">兑换积分</div>
                <div field="id" width="100" allowSort="true" renderer="onShengRenderer" >剩余积分</div>
                <!--<div field="state" width="100" allowSort="true"  renderer="onStateRenderer">状态</div>-->
                <div field="eamil" width="100" allowSort="true">邮箱</div>
                <!--
                <div field="extensionNumber" width="100" allowSort="true" renderer="onNumberRenderer">下线数</div>
                -->
                <div field="phone"  allowSort="true">手机号</div>
                <div field="register" width="100" allowSort="true">注册时间</div>
                <div field="id"  headerAlign="center"  renderer="onHandleRenderer" width="70" >操作</div>
                <div field="IP"  headerAlign="center" allowSort="true" >IP</div>
                   <div field="version"  headerAlign="center" allowSort="true" >版本号</div>
                   <div field="IDFA"  headerAlign="center" allowSort="true" >IDFA</div>
                   <div field="UDID"  headerAlign="center" allowSort="true" >UDID</div>
                   <div field="MAC"  headerAlign="center" allowSort="true" >MAC</div>
                   <div field="IMEI"  headerAlign="center" allowSort="true" >IMEI</div>
            </div>
        </div> 
    </div>
    
    <!--添加和编辑页面-->
   <div id="editWindow" class="mini-window" title="会员增减积分" style="width:480px;display: none;" showModal="true" allowResize="true" iconCls="icon-save" allowDrag="true" >
	    <div id="editform"  class="form">
	      <input class="mini-hidden" name="id"/>
	      <input class="mini-hidden" name="registerdate"/>
	      <fieldset style="100%;border:solid 1px #aaa;margin-top:8px;position:relative;">
          <legend>信息</legend>
	        <table style="width:100%;">
	            <tr>
	                <td style="width:60px;" align="right">用户id：</td>
	                <td style="width:150px;"><input name="userid" id="userid" required="true"   vtype="english" class="mini-textbox" /></td>
	                <td style="width:60px;" align="right">用户昵称：</td>
	                <td style="width:150px;"><input name="username" id="username" required="true"    class="mini-textbox"  /></td>
	            </tr>
	            <tr>
	                <td style="width:60px;" align="right">类型：</td>
	                <td style="width:150px;"><input name="type" id="type" required="true"  class="mini-combobox"  data="addstate"/></td>
	                <td style="width:60px;" align="right">分数：</td>
	                <td style="width:150px;"><input name="number" id="number" required="true"  vtype="int"  class="mini-textbox"  /></td>
	            </tr>
	            <tr>
	                <td style="width:60px;" align="right">备注：</td>
	                <td  colspan="3"><textarea class="mini-textarea" vtype="maxLength:100"  name="remark" emptyText="请输入备注" style="width:85%;"></textarea></td>
	            </tr>
	        </table>
	        </fieldset>
	       <div align="right" style="padding: 10px">
                  <a class="mini-button" iconCls="icon-save" href="javascript:saveRow()">增加</a> 
                  <a class="mini-button" iconCls="icon-close" href="javascript:cancelRow()">关闭</a>
	       </div>       
	    </div>
	</div>
	
	<!-- 积分记录 -->
	 <div id="PanelTopUpWindow" class="mini-window" iconCls="icon-node" title="记录" style="width:600px;height:400px;display: none;" showModal="true" allowResize="true"  allowDrag="true">
        <div class="mini-fit" >
	        <div id="datagridTopUp" class="mini-datagrid" style="width:100%;height: 100%;" 
	            borderStyle="border:0" showPageSize="false" allowAlternating="true" showPageIndex="false"  sizeList="[5,10,20,50]" pageSize="20"
	            url="/ios/pages/ObtainIntegral/list.do">
	            <div property="columns">
	            	<div type="indexcolumn" width="20"></div>
	            	<div field="userid"   headerAlign="center" allowSort="true" >用户ID</div>
	                <div field="username"   headerAlign="center" allowSort="true" >用户昵称</div>
	                <div field="number"  headerAlign="center"  allowSort="true">获得积分</div>
	                <div field="crdate" headerAlign="center"  allowSort="true">时间</div>
	                <div field="remark" headerAlign="center"  allowSort="true">备注</div>
	                <div field="type"  headerAlign="center"  renderer="onTypeRenderer" >类型</div>
	            </div>
	        </div> 
	    </div>     
    </div>
    
    <!-- 用户下线 -->
	 <div id="UserWindow" class="mini-window" iconCls="icon-node" title="下线" style="width:600px;height:400px;display: none;" showModal="true" allowResize="true"  allowDrag="true">
        <div class="mini-fit" >
	        <div id="datagridUser" class="mini-datagrid" style="width:100%;height: 100%;" 
	            borderStyle="border:0" showPageSize="false" allowAlternating="true" showPageIndex="false"  sizeList="[5,10,20,50]" pageSize="20"
	            url="/ios/pages/User/list.do">
	            <div property="columns">
	            	<div type="indexcolumn" width="20"></div>
	            	<div field="userid"   headerAlign="center" allowSort="true" >用户ID</div>
	                <div field="username"   headerAlign="center" allowSort="true" >用户昵称</div>
	            </div>
	        </div> 
	    </div>     
    </div>
    
    <script type="text/javascript">
        var state = [{ id: 1, text: '不在线' }, { id: 2, text: '在线'}];
        var addstate = [{ id: 0, text: '增加' }, { id: 1, text: '减少'}];
        mini.parse();
 		var form = new mini.Form("#editform");
        var editWindow = mini.get("#editWindow");
        var grid = mini.get("datagrid1");
        
         var datagridTopUp=mini.get("datagridTopUp");
         var PanelTopUp = mini.get("PanelTopUpWindow");
         
         var datagridUser=mini.get("datagridUser");
         var UserWindow = mini.get("UserWindow");
        
        grid.load();
        
        mini.get("userid").allowInput=false;
        mini.get("username").allowInput=false;
        
        function onStateRenderer(e) {
            for (var i = 0, l = state.length; i < l; i++) {
                var g = state[i]; if (g.id == e.value) return g.text;
            }
            return "";
        }
        
        var type = [{ id: 1, text: '获取' }, { id: 2, text: '管理员增减'},{ id: 3, text: '邀请送积分'}];
        function onTypeRenderer(e){
            for (var i = 0, l = type.length; i < l; i++) {
                var g = type[i]; if (g.id == e.value) return g.text;
            }
            return "";
        }
        
        function PanelTopUpShow(userid){
             datagridTopUp.load({
                userid:userid
             });
             PanelTopUp.show();
        }
        
        function UserShow(id){
             datagridUser.load({
                paterid:id
             });
             UserWindow.show();
        }
        
        function onShengRenderer(e) {
            var record = e.record;
            return record.integral-record.huIntegral;
        }
        
         function onUserIDRenderer(e) {
           var record = e.record;
           var userid = record.userid;
           return '&nbsp;&nbsp;<a class="New_Button" href="javascript:PanelTopUpShow(\''+userid+'\');">'+e.value+'</a>';
        }
        
        function onNumberRenderer(e) {
           var record = e.record;
           var number = record.extensionNumber;//
           if(number==0){
              return 0;
           }else{
	           return '<a class="New_Button" href="javascript:UserShow(\''+record.id+'\');">'+e.value+'</a>';
           }
        }
        
        function onHandleRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var id = record.id;
            var s ='';
            s =s+'&nbsp;&nbsp;<a class="New_Button" href="javascript:editRow(\''+id+'\');">增减积分</a>';
            return s;
        }	
        
        function newRow() { 
            form.clear();  
            editWindow.show();
        }
        
         function search() {    
            var datebegin = mini.get("datebegin").getFormValue();
            var dateend = mini.get("dateend").getFormValue();
           // var type = mini.get("statetype").getValue();
            var key = mini.get("key").getValue();
            var IP = mini.get("ip").getValue();
            if(type==''){
              type=0;
            }
            grid.load({userid:key,registerbegin:datebegin,registerend:dateend,IP:IP});
            grid.clearSelect();
        }
        
         function editRow(id) {
            editWindow.show();
            form.clear();
            form.loading();
            $.ajax({
                url: "/ios/pages/User/getId.do?id="+id,
                success: function (text) {
                    form.unmask();
                    var o = mini.decode(text);
                    form.setData(o);
                    initprovince(o);
                    mini.get("tableId").allowInput=false;
                },
                error: function () {
                    alert("表单加载错误");
                    form.unmask();
                }
            }); 
        }
        
        function cancelRow() {
            editWindow.hide();
        }
        
        function saveRow() {
            form.validate();
            if (form.isValid() == false) return;
            var data = form.getData();
            var json = mini.encode(data);
            form.loading();
            $.ajax({
                url: "/ios/pages/ObtainIntegral/save.do",
                type: "post",
                data: {submitData:json },
                success: function (text) {
                    var o = mini.decode(text);
                     if(o.state){
                         form.unmask();
                         grid.load();
                         editWindow.hide();
                     }else{
                         form.unmask();
                         alert("保存出错了!");
                     }
                },
                error: function (jqXHR, textStatus, errorThrown) {
			         alert("请求出错了!");
			    }
            });
        }
        
        function reset() { 
            form.clear();        
        }
        
        function removeRow() {
         	var rows = grid.getSelecteds();
         	var ids="";
         	for(i=0;i<rows.length;i++){
         	    ids+="'"+rows[i].id+"',";
         	}
         	mini.confirm("确定删除记录？", "确定？",
	            function (action, value) {            
	                if (action == "ok") {
		                 if (rows.length>0) {
	                    	var messageid = mini.loading("正在执行...", "wait");
			                $.ajax({
			                    url: "/ios/pages/User/delete.do?id="+ids,
			                    success: function (text) {
			                       var o = mini.decode(text);
			                       mini.hideMessageBox(messageid);
                     			   if(o.state){
			                          grid.load();
                     			   }else{
                     			      mini.alert("删除出错");
                     			   }
			                    },
			                    error: function () {
			                   		mini.hideMessageBox(messageid);
			                   		mini.alert("删除出错");
			                    }
			                });
		                } else {
		                    return;
		            	}
	               }else{
	                  return;
	               }
            },true);
        }
        
        function downloadData(){
            var datebegin = mini.get("datebegin").getFormValue();
            var dateend = mini.get("dateend").getFormValue();
            var key = mini.get("key").getValue();
            var IP = mini.get("ip").getValue();
            var url="/ios/pages/User/exportData.do?userid="+key+"&registerbegin="+datebegin+"&registerend="+dateend+"&IP="+IP;
            window.location.href=url;
         }
    </script>
</body>
</html>